package com.dg11185.nearshop.net.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.dg11185.nearshop.net.entity.Area;

/**
 * @author : daibo
 * @version : 2014-5-15 下午9:21:56
 * @see :
 */
public class GetProvinceListResponse {

    public NetStatus status = null;

    public List<Area> areas = null;

    public String responseStr;
    public GetProvinceListResponse() {
        areas = new ArrayList<Area>();
    }

    public void parseJson(String response) {
        responseStr = response;
        System.out.println(response);
        try {
            JSONObject jsonObject = new JSONObject(response);
            status = NetStatus.getStatus(jsonObject.optString("status"));

            if (!jsonObject.isNull("areaList")) {
                JSONArray areaArray = jsonObject.optJSONArray("areaList");

                for (int a = 0; a < areaArray.length(); a++) {
                    Area area = new Area();
                    area.parseEntity(areaArray.getJSONObject(a));
                    areas.add(area);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
